﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ATCAssistant.Properties;

namespace ATCAssistant
{
    public partial class ManageToolsDialog : Form
    {
        public ManageToolsDialog()
        {
            InitializeComponent();
        }

        private void ManageToolsDialog_Load(object sender, EventArgs e)
        {
            gridTools.Rows.Clear();
            foreach (DictionaryEntry toolEntry in Settings.Default.ExternalTools)
            {
                string[] item = { toolEntry.Value.ToString(), toolEntry.Key.ToString() };
                gridTools.Rows.Add(item);
            }
        }

        private void cmdOk_Click(object sender, EventArgs e)
        {
            Settings.Default.ExternalTools.Clear();
            foreach (DataGridViewRow row in gridTools.Rows)
            {
                // skip invalid rows
                if (row.Cells[0].Value == null || row.Cells[1].Value == null)
                    continue;

                // add this row to the external tools list
                Settings.Default.ExternalTools.Add(
                    row.Cells[1].Value.ToString(),
                    row.Cells[0].Value.ToString());
            }
            this.DialogResult = DialogResult.OK;
        }

        private void cmdCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
        }
    }
}
